﻿using System;

namespace out参数
{
	//当一个函数要返回多个类型的值时用的；
	//out参数侧重于一个方法返回多个类型的值;
	class Program
	{
		static void Main(string[] args)
		{
			#region  计算一个整数数组的最大值，最小值，平均值，总和
			//int max, min, sum, avg;
			//string s;
			//int[] numb = new int[] { 1, 3, 4, 5, 67, 8, 4 };
			//Test(numb, out max, out min, out sum, out avg,out s);
			//Console.WriteLine("最大值{0}，最小值{1}，平均值{3}，总和{2},string{4}",max, min, sum, avg,s);
			#endregion
			#region 用out做一个简单的练习
			Console.WriteLine("请输入用户名");
			string userName = Console.ReadLine();
			Console.WriteLine("请输入密码");
			string userPwd = Console.ReadLine();
			string msg;
			bool b = IsLogin(userName, userPwd, out msg);
			Console.WriteLine("登录结果"+b);
			Console.WriteLine("登录信息"+msg);
			Console.ReadKey();
			#endregion
		}
		public static bool IsLogin(string name,string pwd,out string msg)
		{
			if (name == "admin" && pwd == "888888") 
			{
				msg = "登录成功";
				return true;
			}
			else if (name == "admin")
			{
				msg = "密码错误";
				return false;
			}
			else if (pwd == "888888")
			{
				msg = "用户名错误";
				return false;
			}
			else
			{
				msg = "未知错误";
				return false;
			}
		}














		/// <summary>
		/// 计算一个整数数组的最大值，最小值，平均值，总和
		/// </summary>
		/// <param name="nums">要求值的数组</param>
		/// <param name="max">最大值</param>
		/// <param name="min">最小值</param>
		/// <param name="sum">总和</param>
		/// <param name="avg">平均值</param>
		public static void Test(int[] nums,out int max,out int min,out int sum,out int avg,out string s)
		{
			s = "33312";
			//out 参数要求在方法的内部必须为其赋值
			max = nums[0];
			min = nums[1];
			sum = 0;
			for(int i = 0; i < nums.Length; i++)
			{
				if (nums[i] > max)
				{
					max = nums[i];
				}
				if (nums[i] < min)
				{
					min = nums[i];
				}
				sum += nums[i];
			}
			avg = sum / nums.Length;
		}


	}
}
